package com.trivera.adhoc;

public abstract class TaxableEntity 
	implements Payable, Comparable<TaxableEntity> {

	private String name;
	private String taxId;

	public TaxableEntity(String name, String taxId) {
		setName(name);
		setTaxId(taxId);
	}
	
	@Override
	public int compareTo(TaxableEntity other) {
		return getTaxId().compareTo(other.getTaxId());
	}

	@Override
	public boolean equals(Object obj) {
		if (obj != null && obj instanceof TaxableEntity)
		{
			TaxableEntity other = (TaxableEntity)obj;
			return getTaxId().equals(other.getTaxId());
		}
		else
			return false;
	}

	@Override
	public int hashCode() {
		return getTaxId().hashCode();
	}



	public void hire (Payable newhire)
	{
		throw new UnsupportedOperationException();
	}
	
	/* (non-Javadoc)
	 * @see com.trivera.adhoc.Payable#pay(float)
	 */
	@Override
	public abstract float pay(float amount);
	
	/* (non-Javadoc)
	 * @see com.trivera.adhoc.Payable#getName()
	 */
	@Override
	public String getName() {
		return name;
	}

	public void setName(String name) {
		if (name != null && name.matches("^[\\w\\s\\.-]{1,30}$"))
			this.name = name;
		else
			throw new IllegalArgumentException ("Invalid Name");
	}

	public String getTaxId() {
		return taxId;
	}

	public void setTaxId(String taxId) {
		if (taxId != null && taxId.matches(getTaxIdRegex()))
			this.taxId = taxId;
		else
			throw new InvalidTaxIdException("taxid must be dd-ddddddd");
	}
	
	protected abstract String getTaxIdRegex();

}
